package com.v1.video.db.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.v1.video.dbcore.greenrobot.dao.AbstractDaoMaster;
import com.v1.video.dbcore.greenrobot.dao.identityscope.IdentityScopeType;

import com.v1.video.db.dao.CacheTBDao;
import com.v1.video.db.dao.VideoTBDao;
import com.v1.video.db.dao.RecommendTBDao;
import com.v1.video.db.dao.StatisticsTBDao;
import com.v1.video.db.dao.OperateTBDao;
import com.v1.video.db.dao.NewRecordTBDao;
import com.v1.video.db.dao.ThemeTBDao;
import com.v1.video.db.dao.MyThemeTBDao;
import com.v1.video.db.dao.ThemeVideoTBDao;
import com.v1.video.db.dao.MyThemeVideoTBDao;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
 * Master of DAO (schema version 7): knows all DAOs.
 */
public class DaoMaster extends AbstractDaoMaster {
	public static final int SCHEMA_VERSION = 7;

	/** Creates underlying database table using DAOs. */
	public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
		CacheTBDao.createTable(db, ifNotExists);
		VideoTBDao.createTable(db, ifNotExists);
		RecommendTBDao.createTable(db, ifNotExists);
		StatisticsTBDao.createTable(db, ifNotExists);
		OperateTBDao.createTable(db, ifNotExists);
		NewRecordTBDao.createTable(db, ifNotExists);
		ThemeTBDao.createTable(db, ifNotExists);
		MyThemeTBDao.createTable(db, ifNotExists);
		ThemeVideoTBDao.createTable(db, ifNotExists);
		MyThemeVideoTBDao.createTable(db, ifNotExists);
	}

	/** Drops underlying database table using DAOs. */
	public static void dropAllTables(SQLiteDatabase db, boolean ifExists) {
		CacheTBDao.dropTable(db, ifExists);
		VideoTBDao.dropTable(db, ifExists);
		RecommendTBDao.dropTable(db, ifExists);
		StatisticsTBDao.dropTable(db, ifExists);
		OperateTBDao.dropTable(db, ifExists);
		NewRecordTBDao.dropTable(db, ifExists);
		ThemeTBDao.dropTable(db, ifExists);
		MyThemeTBDao.dropTable(db, ifExists);
		ThemeVideoTBDao.dropTable(db, ifExists);
		MyThemeVideoTBDao.dropTable(db, ifExists);
	}

	public static abstract class OpenHelper extends SQLiteOpenHelper {

		public OpenHelper(Context context, String name, CursorFactory factory) {
			super(context, name, factory, SCHEMA_VERSION);
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			Log.i("greenDAO", "Creating tables for schema version "
					+ SCHEMA_VERSION);
			createAllTables(db, false);
		}
	}

	/** WARNING: Drops all table on Upgrade! Use only during development. */
	public static class DevOpenHelper extends OpenHelper {
		public DevOpenHelper(Context context, String name, CursorFactory factory) {
			super(context, name, factory);
		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			Log.i("greenDAO", "Upgrading schema from version " + oldVersion
					+ " to " + newVersion + " by dropping all tables");
			// dropAllTables(db, true);
			// onCreate(db);
			// start ��ݿ�4.1�汾��
			if (oldVersion < 2) {
				NewRecordTBDao.createTable(db, false);
			}
			// end ��ݿ�4.1�汾��
			// start ��ݿ�4.3�汾��
			if (oldVersion < 4) {
				ThemeTBDao.createTable(db, false);
				MyThemeTBDao.createTable(db, false);
				ThemeVideoTBDao.createTable(db, false);
				MyThemeVideoTBDao.createTable(db, false);
			}
			// end ��ݿ�4.3�汾��
			MigrationHelper.getInstance().migrate(db, CacheTBDao.class,
					VideoTBDao.class, RecommendTBDao.class,
					StatisticsTBDao.class, OperateTBDao.class,
					NewRecordTBDao.class, ThemeTBDao.class, MyThemeTBDao.class,
					ThemeVideoTBDao.class, MyThemeVideoTBDao.class);
		}
	}

	public DaoMaster(SQLiteDatabase db) {
		super(db, SCHEMA_VERSION);
		registerDaoClass(CacheTBDao.class);
		registerDaoClass(VideoTBDao.class);
		registerDaoClass(RecommendTBDao.class);
		registerDaoClass(StatisticsTBDao.class);
		registerDaoClass(OperateTBDao.class);
		registerDaoClass(NewRecordTBDao.class);
		registerDaoClass(ThemeTBDao.class);
		registerDaoClass(MyThemeTBDao.class);
		registerDaoClass(ThemeVideoTBDao.class);
		registerDaoClass(MyThemeVideoTBDao.class);
	}

	public DaoSession newSession() {
		return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
	}

	public DaoSession newSession(IdentityScopeType type) {
		return new DaoSession(db, type, daoConfigMap);
	}

}
